<template>
  <el-dialog
    class="dialog"
    :title="title"
    :visible.sync="show"
    width="400px"
    :before-close="close">
    <el-form ref="form" :model="form" label-width="100px">
      <el-form-item label="分配学科" v-if="this.title !== '生成审核员'">
        <!-- <el-input v-model="form.subject"></el-input> -->
        <el-select @change="changesValue" v-model="form.subject" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="当前项目数量">
        <el-input :disabled="true"  v-model="form.allnumber"></el-input>
      </el-form-item>
      <el-form-item label="生成数量">
        <el-input v-model="form.number"></el-input>
      </el-form-item>
      
      
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="add">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script type="text/ecmascript-6">
import { option } from "./option";
export default {
  props: {
    show: Boolean,
    title: String,
    value: Number
  },
  data() {
    return {
      form: {
        name: null,
        number: null,
        allnumber: null,
        subject: null
      },
      options: option
    };
  },
  watch: {
    title: function(val) {
      console.log(val)
      this.form = {
        name: null,
        number: null,
        allnumber: null,
        subject: null
      }
      if(val === '生成审核员') {
        this.select_project();
      }
    }
  },
  methods: {
    changesValue(val) {
      console.log(val)
      this.form.allnumber = null
      this.$http.get('/filing/manager/project/subject/sum', {
        params: {
          subject: `${val}`
        }
      }).then(res => {
        console.log(res)
        
        this.form.allnumber = res.data.total;
      })
    },
    select_project() {
      console.log('13123')
      this.form.allnumber = null
      this.$http.get("/filing/manager/project/sum").then(res => {
        this.form.allnumber = res.data.total;
      });
    },
    close() {
      this.$emit("close");
    },
    add() {
      if (this.title === "生成审核员") {
        let data = {
          numb: this.form.number
        };
        this.$http.post(`/common/user/auditor/add`, data).then(res => {
          this.$message("生成成功！");
          this.$emit("updata");
        });
      } else {
        let data = {
          numb: this.form.number,
          subject: this.form.subject
        };
        this.$http.post(`/common/user/judges/add`, data).then(res => {
          this.$message("生成成功！");
          this.$emit("updata");
        });
      }
      this.close();
    }
  }
};
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
